package minatest;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;


public class Server 
{
	public static void main(String args[])throws Exception
	{
		ByteBuffer.setUseDirectBuffers(false);
		ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
		
		IoAcceptor acceptor=new SocketAcceptor();
		SocketAcceptorConfig cfg=new SocketAcceptorConfig();
		cfg.getFilterChain().addLast("logger",new LoggingFilter());
		cfg.getFilterChain().addLast("codec",new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
		acceptor.bind(new InetSocketAddress(5222),new MySocketHandler(),cfg);	
		
		/*Socket socket=new Socket("localhost",5222);
		DataOutputStream dos=new DataOutputStream(socket.getOutputStream());
		DataInputStream dis=new DataInputStream(socket.getInputStream());
		dos.writeUTF("dakiler");
		dos.flush();
		System.out.println("client sent...");
		String input=dis.readUTF();
		System.out.println("receive in client:"+input);*/
	}
}
